package com.dayatang.exam.domain;

import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;

import org.hibernate.annotations.CacheConcurrencyStrategy;

/**
 * 判断题答�?
 * @author yang
 *
 */
@Entity
@DiscriminatorValue("J")
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class JudgementSolution extends QuestionSolution implements ObjectiveQuestionSolution {

	private static final long serialVersionUID = -5569987518000249843L;

	public JudgementSolution() {
	}

	public JudgementSolution(JudgementQuestion question, int point, int position) {
		super(question, point, position);
	}

	@Override
	public JudgementQuestion getQuestion() {
		return getRepository().get(JudgementQuestion.class, getQuestion().getId());
	}

	/**
	 * 计算得分
	 */
	public void calculateScore() {
		if (getSolution() == null) {
			return;
		}
		if (getQuestion().isCorrect(getSolution())) {
			setScore(getPoint());
		} else {
			setScore(0);
		}
	}
}
